package com.atm.atmsys.controller.admin;


import com.atm.atmsys.Service.AdminService;
import com.atm.atmsys.dto.AdminDTO;
import com.atm.atmsys.dto.AdminPageQueryDTO;
import com.atm.atmsys.entity.AdminInfo;
import com.atm.atmsys.entity.PageResult;
import com.atm.atmsys.utils.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
@Slf4j
public class AdminController {

    @Autowired
    private AdminService adminService;

    //新增银行管理员
    @PostMapping("/addAdmin")
    @ApiOperation("新增银行管理员")
    public Result addAdmin(@RequestBody AdminInfo adminInfo) {
        log.info("新增银行管理员:{}",adminInfo);
        adminService.addAdmin(adminInfo);
        System.out.println(adminInfo);
        return Result.success();


    }
    //删除银行管理员
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除银行管理员")
    public Result deleteAdmin(@PathVariable Integer id) {
        log.info("删除银行管理员,id:{}",id);
        adminService.deleteAdmin(id);
        return Result.success();
    }

    //根据id查询银行管理员信息
    @GetMapping("/{id}")
    @ApiOperation("根据id查询银行管理员信息")
    public Result<AdminInfo> getAdminById(@PathVariable Integer id) {
        log.info("根据id查询银行管理员信息,id:{}",id);
        AdminInfo adminInfo=adminService.getAdminById(id);
        return Result.success(adminInfo);
    }
    //修改银行管理员信息
    @PutMapping("/updateAdmin")
    @ApiOperation("修改银行管理员信息")
    public Result updateAdmin(@RequestBody AdminDTO adminDTO) {
        log.info("修改银行管理员信息:{}",adminDTO);
        adminService.updateAdmin(adminDTO);
        return Result.success();
    }

    //查询所有银行管理员信息
    @GetMapping("/page")
    @ApiOperation("分页查询银行管理员信息")
    public Result<PageResult> page(AdminPageQueryDTO adminPageQueryDTO){
        log.info("管理员分页查询，参数为：{}",adminPageQueryDTO);
        PageResult pageResult=adminService.pageQuery(adminPageQueryDTO);
        return Result.success(pageResult);

    }


    @GetMapping("/getIdbyName")
    @ApiOperation("根据管理员名称查询管理员id")
    public Result getIdbyName(String name){
        log.info("根据管理员名称查询管理员id，参数为：{}",name);
        Integer id=adminService.getIdbyName(name);
        return Result.success(id);
    }
}
